import request from '@/utils/request'
import { data } from 'dom7'
export const getPermissionList = params => request({
    url: 'permissions',
    params
})
export const addPermissionList = data => request({
    url: 'permissions',
    data,
    method: 'post'

})
export const getMenusList = () => request({
    url: 'menus',
})
export const delPermissionApi = id => request({
    url: 'permissions/' + id,
    method: 'delete'
})
export const getPermissionInfoList = id => request({
    url: 'permissions/' + id,
})
export const EditPermissionInfoList = data => request({
    url: 'permissions/' + data.id,
    method: 'put',
    data
})
//数组扁平化
export function tree(arr) {
    let newList = [];
    arr.forEach((element) => {
        if (element.childs || element.points) {
            newList.push(...tree(element.childs || element.points));
        }
        newList.push({
            title: element.title,
            id: element.id,
            pid: element.pid,
            title: element.title,
        });
    });
    return newList;
};
//转为树
export function tranListTreeData(list, rootValue) {
    const arr = [];
    list.forEach(item => {
        if (item.pid === rootValue) {
            const children = tranListTreeData(list, item.id)
            if (children.length) item.children = children
            arr.push(item)
        }

    })
    return arr
}